home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr52 / random12.zip / RANDOM.PRG next >
Text File  |  1993-04-11  |  3KB  |  55 lines

  1. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2. * Program..: RANDOM.PRG v 1.1                                                 *
  3. * Author...: Allen Jackson                                                    *
  4. * Date.....: 05-28-1990                                                       *
  5. * Copyright: This program is hereby donated to the public domain.             *
  6. *                                                                             *
  7. * Notes....: This program generates a different psuedo-random number between  *
  8. *            0 and 1 for each iteration.  It generates a different number     *
  9. *            each second because the seed used is based on the internal       *
  10. *            clock.  Originally, I had implemented it as a function, but      *
  11. *            some dBASE dialects could not handle it.  Implementation as a    *
  12. *            function is left to the user.                                    *
  13. *                                                                             *
  14. *            I know there are ways to generate the numbers quicker, but I've  *
  15. *            not yet found a way other than this that works in EVERY dialect. *
  16. *            For example, FoxPro now includes a RAND() function that is far   *
  17. *            superior to this kludge.                                         *
  18. *                                                                             *
  19. *            If you use this program and have any questions or comments,      *
  20. *            drop me a note at:                                               *
  21. *                                                                             *
  22. *                             MCS Consulting                                  *
  23. *                             8125 Starwood Court                             *
  24. *                             Baton Rouge, LA  70820                          *
  25. *                                                                             *
  26. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  27.  
  28. CLEAR
  29. SET TALK OFF
  30. SET ESCAPE ON
  31. SET BELL OFF
  32. SET DECIMAL TO 0
  33.  
  34. DO WHILE .T.
  35.  
  36.    * Wait for clock to change to insure good seeds
  37.    currtime = TIME()
  38.    DO WHILE TIME() = currtime  
  39.    ENDDO
  40.  
  41.    t = TIME()
  42.    seed = VAL(SUBSTR(t,1,2)+SUBSTR(t,4,2)+SUBSTR(t,7,2))
  43.    rnd = MOD(seed*7137421+21132487,10000000)/10000000
  44.  
  45.    * 'rnd' is a number between 0 and 1
  46.    * Set 'randomnum' equal to '(rnd() * x)' where 'x' is the number you
  47.    * want to use as the maximum number to be generated.  For example:
  48.    
  49.    randomnum = rnd * 3  
  50.    @ 12,32 SAY randomnum
  51.  
  52. ENDDO
  53.  
  54. RETURN
  55.